package cn.picclife.mwx.common.core.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import com.alibaba.fastjson.JSON;

import cn.picclife.mwx.common.web.base.BaseResult;

public class RestUtils1 {
	private final static Logger logger = LoggerFactory.getLogger(RestUtils1.class);
	
	public static void error(HttpServletResponse response, BaseResult baseResult){
		response.setContentType(MediaType.APPLICATION_JSON_VALUE); // 设置ContentType
		response.setCharacterEncoding("UTF-8"); // 避免乱码
		response.setHeader("Cache-Control", "no-cache,must-revalidate");
		try {
			PrintWriter writer = response.getWriter();
			response.setStatus(HttpStatus.BAD_REQUEST.value());
			writer.write(JSON.toJSONString(baseResult));
			writer.close();
		} catch (IOException e) {
			logger.error("Rest处理返回结果异常", e);
		}
	}
}
